#include "DAEMatrix33.h"

DAEMatrix33::DAEMatrix33(void)
{
}

DAEMatrix33::~DAEMatrix33(void)
{
}

void DAEMatrix33::SetCell(int row, int column, float value)
{
	m_RMData[row*3+column]=value;
}

float DAEMatrix33::GetCell(int row, int column) const
{
	return m_RMData[row*3+column];
}

void DAEMatrix33::SetRow(int row, DAEFloat3& value)
{
	m_RMData[row*3]   = value.x;
	m_RMData[row*3+1] = value.y;
	m_RMData[row*3+2] = value.z;
}

void DAEMatrix33::SetRow(int row, float a1, float a2, float a3)
{
	m_RMData[row*3]   = a1;
	m_RMData[row*3+1] = a2;
	m_RMData[row*3+2] = a3;
}

void DAEMatrix33::SetColumn(int column, DAEFloat3& value)
{
	m_RMData[column]      = value.x;
	m_RMData[3 + column]  = value.y;
	m_RMData[6 + column]  = value.z;
}
	
void DAEMatrix33::SetColumn(int column, float a1, float a2, float a3)
{
	m_RMData[column]      = a1;
	m_RMData[3 + column]  = a2;
	m_RMData[6 + column]  = a3;
}

void DAEMatrix33::GetRow(int row, DAEFloat3& value) const
{
	value.x = m_RMData[row*3];
	value.y = m_RMData[row*3+1];
	value.z = m_RMData[row*3+2];
}
	
void DAEMatrix33::GetColumn(int column, DAEFloat3& value) const
{
	value.x = m_RMData[column];
	value.y = m_RMData[3+column];
	value.z = m_RMData[6+column];
}


void DAEMatrix33::SetAsIdentity()
{
	this->SetRow(0,1,0,0);
	this->SetRow(1,0,1,0);
	this->SetRow(2,0,0,1);
}

float DAEMatrix33::Determinant() const
{
	return m_RMData[0]*(m_RMData[4]*m_RMData[8]-m_RMData[5]*m_RMData[7])
		-m_RMData[1]*(m_RMData[3]*m_RMData[8]-m_RMData[5]*m_RMData[6])
		+m_RMData[2]*(m_RMData[3]*m_RMData[7]-m_RMData[4]*m_RMData[6]);
}
